package com.lh.dao;

import com.lh.entity.Advertisement;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @Author: LuoHang
 * @Date: 2021/2/14 0:11
 * @Description
 */
@Repository
public class AdvertisementDao {
    @Autowired
    private SqlSessionTemplate sessionTemplate;

    public List<Advertisement> getAdvertisements(Map<String,Object> map){
        return sessionTemplate.selectList("AdvertisementMapper.getAdvertisements",map);
    }

    public int getCount(Map<String,Object> map){
        return sessionTemplate.selectOne("AdvertisementMapper.getCount",map);
    }

    public Advertisement getAdvertisementById(Integer id){
        return sessionTemplate.selectOne("AdvertisementMapper.getAdvertisementById",id);
    }

    public int addAdvertisement(Advertisement advertisement){
        return sessionTemplate.insert("AdvertisementMapper.addAdvertisement",advertisement);
    }

    public int updateAdvertisement(Map<String,Object> map){
        return sessionTemplate.update("AdvertisementMapper.updateAdvertisement",map);
    }

    public int deleteAdvertisementById(Integer id){
        return sessionTemplate.delete("AdvertisementMapper.deleteById",id);
    }
}
